using System;
using System.Diagnostics;

using org.fourzoas.noise.module;

namespace org.fourzoas.noise.module {
  /// <summary>
  /// Noise module that outputs a checkerboard pattern.
  /// </summary>
  /// <remarks>
  /// <img src="file://C:/temp/noise/noise/doc/html/modulecheckerboard.png"/>
  /// <para>
  /// This noise module outputs unit-sized blocks of alternating values.
  /// The values of these blocks alternate between -1.0 and +1.0.
  ///</para>
  /// <para>
  /// This noise module is not really useful by itself, but it is often used
  /// for debugging purposes.
  ///</para>
  /// <para>
  /// This noise module does not require any source modules.
  /// </para>
  /// </remarks>
  public class Checkerboard : GeneratorModule {
    /// <summary>
    /// Default constructor.
    /// </summary>
    public Checkerboard() : base(0) { }
    /// <summary>
    /// Returns the number of source modules required by this noise module.
    /// </summary>
    /// <returns>The number of source modules required by this noise module.</returns>
    public override int GetSourceModuleCount() {
      return 0;
    }
    /// <summary>
    /// Generates an output value given the coordinates of the specified input value.
    /// </summary>
    /// <param name="x">The <em>x</em> coordinate of the input value.</param>
    /// <param name="y">The <em>y</em> coordinate of the input value.</param>
    /// <param name="z">The <em>z</em> coordinate of the input value.</param>
    /// <returns>The output value.</returns>
    public override double GetValue(double x, double y, double z) {
      long ix = (long) (Math.Floor(Globals.MakeInt64Range(x)));
      long iy = (long) (Math.Floor(Globals.MakeInt64Range(y)));
      long iz = (long) (Math.Floor(Globals.MakeInt64Range(z)));
      return ((ix & 1 ^ iy & 1 ^ iz & 1) != 0) ? -1.0 : 1.0;
    }
  }
}